// components/marker-popup.js
const {
  addMarker
} = require("../../utils/api")
import Notify from '@vant/weapp/notify/notify';
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    title: '',
    cost: '',
    //弹窗显示
    markerFormShow: false,
    markerForm: {},
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickoverlay() {
      this.triggerEvent("dialogClose")
    },
    async submit() {
      const form = {
        ...this.data.markerForm
      }
      if (!this.data.title) {
        form.title = form.recommend
      } else {
        form.title = this.data.title
      }
      form.cost = this.data.cost
      const res = await addMarker(form);
      if(res.data.meta.status==200){
        Notify({
          type: 'success',
          message: res.data.data,
        });
        this.setData({
          markerFormShow: false
        })
        this.triggerEvent("dialogClose")
      }
    },
    cancel() {
      Notify({
        type: 'primary',
        message: '已退出标点模式'
      });
      this.setData({
        markerFormShow: false
      })
      this.triggerEvent("dialogClose")
    },
    onClose() {}
  }
})